export default {
  tree_out_invoice: {
    _odoo_model: 'ir.ui.view',
    model: 'fp.fapiao',
    type: 'tree',

    toolbar: {
      action: [
        {
          name: '确认',
          id: 'fapiao.action_fapiao_confirm',
          xml_id: 'fapiao.action_fapiao_confirm'
        },
        {
          name: '开票',
          id: 'fapiao.action_fapiao_request',
          xml_id: 'fapiao.action_fapiao_request'
        },
        {
          name: '开票查询',
          id: 'fapiao.action_fapiao_request_read',
          xml_id: 'fapiao.action_fapiao_request_read'
        },
        {
          name: '回写结果',
          id: 'fapiao.action_fapiao_send_result',
          xml_id: 'fapiao.action_fapiao_send_result'
        }
      ]
    },

    fields: {
      name: {},
      // draw_ids: {},
      // draw_id: {},

      type: { string: '进销项类型' },
      invoice_type: { string: '种类' },
      state: {
        string: '发票状态',
        selection: [
          ['draft', '草稿'],
          ['confirmed', '已确认'],
          ['doing', '开票中'],
          ['done', '已开票'],
          ['error', '开票失败']
          // ['posted', '已过账'],
          // ['cancel', '已取消']
        ]
      },

      company_id: { string: '公司' },

      buyer_name: { string: '购买方' },
      // buyer_tin: { string: '税号' },
      // buyer_address_phone: { string: '地址电话' },
      // buyer_bank_account: { string: '银行账户' },

      saler_name: { string: '销售方' },
      // saler_tin: { string: '税号' },
      // saler_address_phone: { string: '地址电话' },
      // saler_bank_account: { string: '银行账户' },

      // name: { string: '名称' },
      // payee_name: { string: '收款人' },
      // checker_name: { string: '复核' },
      // drawer_name: { string: '开票人' },

      type_code: { string: '发票代码' },
      code: { string: '发票号码' },
      // check_code: { string: '校验码' },
      date_order: { string: '开票日期' },
      // note: { string: '备注' },
      // amount_untaxed: { string: '不含税合计' },
      // amount_tax: { string: '税合计' },
      amount_total: { string: '价税合计' }
      // cn_amount_total: { string: '价税合计大写' }
    }
  },

  form_out_invoice: {
    _odoo_model: 'ir.ui.view',
    model: 'fp.fapiao',
    type: 'form',

    arch: {
      header: {
        buttons: [
          {
            name: 'action_confirm',
            string: '确认',
            type: 'object',
            btn_type: 'primary',
            invisible: ({ record }) => {
              const { state } = record
              return state !== 'draft'
            }
          },

          {
            name: 'action_post',
            string: '过账',
            type: 'object',
            btn_type: 'primary',
            invisible: ({ record }) => {
              const { state } = record
              return !['done', 'confirmed'].includes(state)
            }
          },

          {
            name: 'action_cancel',
            string: '取消',
            type: 'object',
            invisible: ({ record }) => {
              const { state } = record
              return state === 'cancel'
            }
          },
          {
            name: 'action_draft',
            string: '重置为草稿',
            type: 'object',
            invisible: ({ record }) => {
              const { state } = record
              return state !== 'cancel'
            }
          }
        ],
        fields: {
          state: {
            widget: 'statusbar',
            statusbar_visible: 'draft,confirmed,doing,done,posted'
          }
        }
      }
    },

    fields: {
      date_fapiao: { string: '开票日期' },

      taxmachine_code: {},

      type: { string: '进销项类型' },
      invoice_type: { string: '种类' },
      state: {
        string: '状态',
        selection: [
          ['draft', '草稿'],
          ['confirmed', '已确认'],
          ['doing', '开票中'],
          ['done', '已开票'],
          ['error', '开票失败']
          // ['posted', '已过账'],
          // ['cancel', '已取消']
        ]
      },

      name: { string: '订单号码' },

      company_id: { string: '公司' },
      user_id: { string: '开票人' },

      attachment_id: { string: '原始单据', widget: 'attachment' },

      buyer_id: { string: '客户' },

      buyer_name: { string: '购买方' },
      buyer_tin: { string: '税号' },
      buyer_phone: { string: '电话' },
      buyer_address: { string: '地址' },

      buyer_address_phone: { string: '地址电话' },
      buyer_bank_account: { string: '银行账户' },

      saler_name: { string: '销售方' },
      saler_tin: { string: '税号' },
      saler_phone: { string: '电话' },
      saler_address: { string: '地址' },
      saler_address_phone: { string: '地址电话' },
      saler_bank_account: { string: '银行账户' },

      payee_name: { string: '收款人' },
      checker_name: { string: '复核' },
      drawer_name: { string: '开票人' },

      type_code: { string: '发票代码' },
      code: { string: '发票号码' },
      check_code: { string: '校验码' },
      date_order: { string: '订单日期' },
      note: { string: '备注' },
      amount_untaxed: { string: '不含税合计' },
      amount_tax: { string: '税合计' },
      amount_total: { string: '价税合计' },
      cn_amount_total: { string: '价税合计大写' },

      line_ids: {
        widget: 'x2many_tree',
        context: {},
        string: '明细行',

        views: {
          tree: {
            fields: {
              // sequence: { string: '序号' },
              // name: { string: '说明' },
              line_type: {},
              vat_product_name: { string: '商品类别' },
              product_name: { string: '货物或应税劳务、服务名称' },
              product_spec: { string: '规格型号' },
              product_uom: { string: '单位' },

              quantity: { string: '数量' },
              price_unit: { string: '单价' },

              tax_ratio: { string: '税率' },

              amount_untaxed: { string: '金额' },
              amount_tax: { string: '税额' }
              // note: {}
              // amount_total: { string: '含税金额' }
            }
          },

          form: {
            fields: {
              type: { invisible: 1 },
              line_type: {},

              sequence: { string: '序号' },
              name: { string: '说明' },
              product_id: { string: '产品', required: 1 },
              vat_product_code: {},
              vat_product_name: {},
              product_name: { string: '货物或应税劳务、服务名称' },
              product_spec: { string: '规格型号' },
              product_uom: { string: '单位' },

              quantity: { string: '数量' },
              price_unit: { string: '单价' },

              tax_ratio: { string: '税率' },

              amount_untaxed: { string: '金额' },
              amount_tax: { string: '税额' }
              // amount_total: { string: '含税金额' }
            }
          }
        }
      }
    }
  },

  search_out_fapiao: {
    _odoo_model: 'ir.ui.view',
    model: 'fp.fapiao',
    type: 'search',
    arch: {
      fields: {
        buyer_name: {
          filter_domain: self => {
            return [
              '|',
              '|',
              ['buyer_name', 'ilike', self],
              ['buyer_tin', 'ilike', self],
              ['name', 'ilike', self]
            ]
          }
        }
      },

      filters: {
        group1: {
          __title: '状态',
          draft: {
            string: '草稿',
            domain: [['state', '=', 'draft']]
          },
          confirmed: {
            string: '已确认',
            domain: [['state', '=', 'confirmed']]
          },
          doing: {
            string: '开票中',
            domain: [['state', '=', 'doing']]
          },
          done: {
            string: '已开票',
            domain: [['state', '=', 'done']]
          },
          cancel: {
            string: '已取消',
            domain: [['state', '=', 'cancel']]
          }
        },

        group2: {
          __title: '开票状态',
          draft2: {
            string: '草稿',
            domain: [['state', '=', 'draft']]
          },
          requested2: {
            string: '待查询',
            domain: [['state', 'in', ['requested', 'reread']]]
          },
          done2: {
            string: '完成',
            domain: [['state', 'in', ['requested', 'reread']]]
          }
        },

        group22: {
          date: { string: '开票日期', date: 'date_fapiao' }
        }
      }
    }
  },

  action_out_fapiao: {
    _odoo_model: 'ir.actions',
    name: '销项发票',
    type: 'ir.actions.act_window',
    res_model: 'fp.fapiao',
    search_view_id: 'search_out_fapiao',
    domain: [['type', '=', 'out_invoice']],
    context: {},
    views: {
      tree: 'tree_out_invoice',
      form: 'form_out_invoice'
    }
  },

  action_out_fapiao_general: {
    _odoo_model: 'ir.actions',
    name: '销项普票',
    type: 'ir.actions.act_window',
    res_model: 'fp.fapiao',
    search_view_id: 'search_out_fapiao',
    domain: [
      ['type', '=', 'out_invoice'],
      ['invoice_type', '=', 'vat_general']
    ],
    context: {},
    views: {
      tree: 'tree_out_invoice',
      form: 'form_out_invoice'
    }
  },
  action_out_fapiao_general_e: {
    _odoo_model: 'ir.actions',
    name: '销项普票电',
    type: 'ir.actions.act_window',
    res_model: 'fp.fapiao',
    search_view_id: 'search_out_fapiao',
    domain: [
      ['type', '=', 'out_invoice'],
      ['invoice_type', '=', 'vat_general_e']
    ],
    context: {},
    views: {
      tree: 'tree_out_invoice',
      form: 'form_out_invoice'
    }
  },

  action_out_fapiao_special: {
    _odoo_model: 'ir.actions',
    name: '销项专票',
    type: 'ir.actions.act_window',
    res_model: 'fp.fapiao',
    search_view_id: 'search_out_fapiao',
    domain: [
      ['type', '=', 'out_invoice'],
      ['invoice_type', '=', 'vat_special']
    ],
    context: {},
    views: {
      tree: 'tree_out_invoice',
      form: 'form_out_invoice'
    }
  },
  action_out_fapiao_special_e: {
    _odoo_model: 'ir.actions',
    name: '销项专电',
    type: 'ir.actions.act_window',
    res_model: 'fp.fapiao',
    search_view_id: 'search_out_fapiao',
    domain: [
      ['type', '=', 'out_invoice'],
      ['invoice_type', '=', 'vat_special_e']
    ],
    context: {},
    views: {
      tree: 'tree_out_invoice',
      form: 'form_out_invoice'
    }
  }
}
